//
//  ByRedPacketComeInListItem.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/13.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellRedPacketComeInListItem.h"

@implementation ByCellRedPacketComeInListItem
{
    UIImageView *_bgView;               // 背景
    UILabel     *_nameLabel;            // 商家名称
    UILabel     *_moneyLabel;           // 金额
    UILabel     *_distanceLabel;        // 距离
}
- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    self.contentView.layer.cornerRadius = 8;
    self.contentView.layer.masksToBounds = true;
    
    // 背景
    _bgView = [UIImageView new];
    _bgView.image = [UIImage imageWithColor:[UIColor redColor]];
    [self.contentView addSubview:_bgView];
    
    // 商家名称
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.numberOfLines = 2;
    _nameLabel.text = @"大森林保险";
    _nameLabel.font = FONT(14);
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    _nameLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_nameLabel];
    
    // 金额
    _moneyLabel = [[UILabel alloc] init];
    _moneyLabel.font = FONT(28);
    _moneyLabel.adjustsFontSizeToFitWidth = true;
    _moneyLabel.textAlignment = NSTextAlignmentCenter;
    _moneyLabel.backgroundColor = [UIColor yellowColor];
    _moneyLabel.textColor = BY_GOLD_COLOR;
    [self.contentView addSubview:_moneyLabel];
    _moneyLabel.layer.cornerRadius = 30;
    _moneyLabel.layer.masksToBounds = true;
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"￥999"];
    [attr addAttribute:NSFontAttributeName value:FONT(14) range:NSMakeRange(0, 1)];
    _moneyLabel.attributedText = attr;
    //    _moneyLabel.layer.shadowColor = [UIColor colorWithWhite:0 alpha:1].CGColor;
    //    _moneyLabel.layer.shadowOffset = CGSizeMake(0, 5);
    //    _moneyLabel.layer.shadowOpacity = 1;
    
    
    // 距离
    _distanceLabel = [[UILabel alloc] init];
    _distanceLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
    _distanceLabel.text = @"300m";
    _distanceLabel.font = FONT(15);
    _distanceLabel.textAlignment = NSTextAlignmentRight;
    _distanceLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_distanceLabel];
    
    
    
    // 布局
    [_bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.equalTo(@10);
        make.right.equalTo(@(-10));
        make.height.equalTo(@40);
    }];
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerX.equalTo(@0);
        make.top.equalTo(_nameLabel.mas_bottom);
    }];
    [_distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(@0);
        make.height.equalTo(@20);
    }];

}

@end
